package cn.org.queue.handler;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.message.MessageExt;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Package: cn.org.queue
 * @ClassName: ReceiveMessageHandler
 * @Description: 消息解析处理
 * @Author: mac-pro
 * @CreateDate: 2019/2/14 上午11:46
 * @Version: 1.0
 */
@Slf4j
public class ReceiveMessageHandler {
    static public String decodeRabbitMessage(byte[] body, String routingKey) {
        if (body.length == 0) {
            log.info("body length is null");
            return null;
        }
        if (StringUtils.isBlank(routingKey)) {
            log.info("routingKey is null");
            return null;
        }
        String msg = new String(body);
        log.info("current time={} received msg={}", LocalDateTime.now(), msg);
        return msg;
    }

    public static void decodeRocketMessage(List<MessageExt> messageExtList,String topic){
        log.info( "{} Receive New Messages:={} ",Thread.currentThread().getName() , messageExtList.size());
        MessageExt msg = messageExtList.get(0);
        if (msg.getTopic().equals(topic)) {
            // 执行TagD的消费
            log.info("current time={} received msg={}", LocalDateTime.now(), msg);
        }
    }
}
